<template>
  <div class="loading-container" :class="{ 'loading-fullscreen': fullscreen }">
    <div class="loading-content">
      <div class="loading-spinner">
        <svg class="circular" viewBox="0 0 50 50">
          <circle class="path" cx="25" cy="25" r="20" fill="none" stroke-width="5" stroke-miterlimit="10"></circle>
        </svg>
      </div>
      <div v-if="text" class="loading-text">{{ text }}</div>
    </div>
  </div>
</template>

<script setup>
defineProps({
  text: {
    type: String,
    default: ''
  },
  fullscreen: {
    type: Boolean,
    default: false
  }
})
</script>

<style lang="scss" scoped>
.loading-container {
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  
  &.loading-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.7);
  }
  
  .loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    border-radius: var(--el-border-radius-base);
    background-color: var(--el-bg-color-overlay);
    box-shadow: var(--el-box-shadow-light);
    
    .loading-spinner {
      width: 50px;
      height: 50px;
      position: relative;
      margin-bottom: 10px;
      
      .circular {
        height: 100%;
        width: 100%;
        animation: loading-rotate 2s linear infinite;
        
        .path {
          animation: loading-dash 1.5s ease-in-out infinite;
          stroke-dasharray: 90, 150;
          stroke-dashoffset: 0;
          stroke-width: 2;
          stroke: var(--el-color-primary);
          stroke-linecap: round;
        }
      }
    }
    
    .loading-text {
      color: var(--el-text-color-regular);
      font-size: var(--el-font-size-small);
      margin-top: 10px;
    }
  }
}

@keyframes loading-rotate {
  100% {
    transform: rotate(360deg);
  }
}

@keyframes loading-dash {
  0% {
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -40px;
  }
  100% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -120px;
  }
}

// 暗黑模式适配
html.dark {
  .loading-container {
    &.loading-fullscreen {
      background-color: rgba(0, 0, 0, 0.7);
    }
    
    .loading-content {
      background-color: var(--el-bg-color-overlay);
    }
  }
}
</style>